package com.wteam.controller;

import com.wteam.PoJo.DTO.region;
import com.wteam.PoJo.VO.fixregion;
import com.wteam.PoJo.VO.regionvo;
import com.wteam.service.MemberService;
import com.wteam.service.OrderService;
import com.wteam.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "收货地址")
@Slf4j
@RequestMapping("/region")
public class RegionController {
    @Autowired
    private MemberService memberService;
    @Autowired
    private OrderService orderService;

    /**
     *
     * @param regionvo
     * @return
     */
    @ApiOperation(value = "添加收货地址")
    @PostMapping("/addaddress")
    public Result AddAddress(@RequestBody @Validated regionvo regionvo) {
        return memberService.AddAddress(regionvo);
    }

    /**
     *
     * @return
     */
    @ApiOperation(value = "查看收货地址(全部)")
    @GetMapping("/listaddress")
    public Result<List<region>> listAddress() {
        return memberService.listAddress();
    }

    /**
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "修改默认地址")
    @PutMapping("/updateaddress/{id}")
    public Result updateAddress(@ApiParam(value = "地址id") @PathVariable Integer id) {
        return memberService.updateAddress(id);
    }

    /**
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "先传地址id查地址，在下单改地址信息")
    @PutMapping("/sendregionid/{id}")
    public Result <region>slectAddress(@ApiParam(value = "地址id") @PathVariable Integer id) {
        return orderService.selectAddress(id);
    }

    /**
     *
     * @param fixregion
     * @param id
     * @return
     */
    @ApiOperation(value = "修改收货地址")
    @PutMapping("/updateregion/{id}")
    public Result updateAddress(@RequestBody @Validated fixregion fixregion,@PathVariable
            @ApiParam("地址id") Integer id) {
        fixregion.setId(id);
        return orderService.updateAddress(fixregion);
    }


}
